package ch.fhnw.qualiscan.application.components;

import ch.fhnw.qualiscan.Config;
import ch.fhnw.qualiscan.application.modals.Profile;
import ch.fhnw.qualiscan.core.LayoutComponent;

import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.themes.BaseTheme;

import eu.livotov.tpt.i18n.TM;

@SuppressWarnings("serial")
public class Navigation extends LayoutComponent {
	
	@Override
	public void buildComponent() {
		setHeight("100%");

		// add the wrappers to the main layout panel
		HorizontalLayout navigationWrap = new HorizontalLayout();
		navigationWrap.setSpacing(true);
		navigationWrap.setHeight("100%");
		navigationWrap.setWidth("");
		navigationWrap.addComponent(dashboardButton());
		navigationWrap.addComponent(settingsButton());
		addComponent(navigationWrap);
	}
	
	private HorizontalLayout dashboardButton() {
		// dashboard
		HorizontalLayout dashboardWrap = new HorizontalLayout();
		dashboardWrap.setHeight("100%");
		dashboardWrap.setStyleName("navItem");
		
		Button dashboardButton = new Button(TM.get("general.dashboard"));
		dashboardButton.setIcon(Config.ICON_HOME);
		dashboardButton.setWidth("100px");
		dashboardButton.setStyleName(BaseTheme.BUTTON_LINK);
		dashboardButton.addListener(new Button.ClickListener() {
			public void buttonClick(ClickEvent event) {
				if(sessionHelper.getUserSession().getRole().getId() == Config.ADMINISTRATOR_ID)
					urlLib.setPage("Admin");
				else
					urlLib.setPage("Dashboard");
			}
		});
		
		// add dashboard
		dashboardWrap.addComponent(dashboardButton);
		dashboardWrap.setComponentAlignment(dashboardButton, Alignment.MIDDLE_CENTER);
		return dashboardWrap;
	}
	
	private HorizontalLayout settingsButton() {
		// profile
		HorizontalLayout profileWrap = new HorizontalLayout();
		profileWrap.setHeight("100%");
		profileWrap.setStyleName("navItem");
		
		Button profileButton = new Button(TM.get("general.settings"));
		profileButton.setIcon(Config.ICON_SETTINGS);
		profileButton.setWidth("100px");
		profileButton.setStyleName(BaseTheme.BUTTON_LINK);
		profileButton.addListener(new Button.ClickListener() {
			public void buttonClick(ClickEvent event) {
				openModal(new Profile());
			}
		});
		
		// add settings
		profileWrap.addComponent(profileButton);
		profileWrap.setComponentAlignment(profileButton, Alignment.MIDDLE_CENTER);
		
		return profileWrap;
	}

}
